package com.xonro.common.histrans.zz.biz.base;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.util.UUIDGener;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.ctx.BOCreateData;
import com.xonro.common.histrans.base.ctx.HistoryTransContext;
import com.xonro.common.histrans.base.model.HistoryTransLogModel;
import com.xonro.common.histrans.base.consts.DrpConst;
import com.xonro.common.histrans.zz.biz.common.DrpProcessTransBiz;
import com.xonro.common.histrans.zz.ctx.DrpProcessCreateContext;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class ProcessBidTeamBiz extends DrpProcessTransBiz {
    @Override
    protected void transProcess0(DrpProcessCreateContext historyTransContext) {
        String createUser = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getCreateUser();
        String bindId = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getId();
        Timestamp startTime = historyTransContext.getProcessCreateContext().getProcessInstanceModel().getStartTime();
        List<BOCreateData> boCreateDataList = new ArrayList<>();
        RowMap mainData = historyTransContext.getMainData();
        SDK.getLogAPI().consoleInfo("获取团队库数据");

        //添加日志
        String mainBOId = UUIDGener.getUUID();
        HistoryTransLogModel logModel = new HistoryTransLogModel();
        historyTransContext.setHistoryTransLogModel(logModel);
        logModel.setBindId(bindId);
        logModel.setBpmBOId(mainBOId);
        logModel.setBpmTable("BO_EU_BID_TEAM_APPLY");//项目基础信息
        logModel.setOuterTable("ct_biddingteamlibrary");//基础项目信息表
        logModel.setOuterPK(mainData.getString("MyId"));
        logModel.setOuterExt1(mainData.getString("TeamName"));//团队名称
        logModel.setOuterExt2(mainData.getString("BillNo"));//单据号
        BOCreateData mainBOCreateData = new BOCreateData();
        boCreateDataList.add(mainBOCreateData);
        BO mainBO = new BO();
        mainBOCreateData.setBo(mainBO);
        mainBOCreateData.setCreateUser(createUser);
        mainBO.setCreateDate(startTime);
        mainBO.setUpdateDate(startTime);
        mainBO.setId(mainBOId);
        mainBO.set("DATA_TYPE",mainData.getString("2"));//历史数据
        mainBO.set("DRP_ID",mainData.getString("MyId"));
        mainBO.set("APPLY_NO",mainData.getString("BillNo"));
        mainBO.set("APPLY_NO",mainData.getString("BillNo"));
        mainBO.set("ID_CARD",mainData.getString("IDCard"));
        mainBO.set("TEAM_CLASS",mainData.getString("TeamType"));
        mainBO.set("TEAM_NAME",mainData.getString("TeamName"));
        mainBO.set("USER_NAME",mainData.getString("Contacts"));
        mainBO.set("SEX",mainData.getString("Sex"));
        mainBO.set("COUNT",mainData.getString("TeamPeopleNumber"));
        mainBO.set("PHONE",mainData.getString("Phone"));
        mainBO.set("MAIL",mainData.getString("Email"));
        mainBO.set("IS_ZBSB",mainData.getString("IsInCompanyWork"));//可以在公司总部(区域)上班
        mainBO.set("IS_BHJS",mainData.getString("IsHavePreparedBy"));//团队包含技术标编制人员
        mainBO.set("ADDRESS",mainData.getString("TeamCity")+mainData.getString("TeamAdress"));//地址
        mainBO.set("TWO_AMOUNT",mainData.getString("BidAmount"));//近两年投标金额(元)
        mainBO.set("TWO_COUNT",mainData.getString("WinningNum"));//近两年中标个数
        mainBO.set("HZYWZX",mainData.getString("BusinessCenter"));//合作业务中心
        mainBO.set("BS_RANGE",mainData.getString("Scope"));//标书制作擅长范围
        mainBO.set("HZ_COMPANY",mainData.getString("CooperatedUnit"));//曾经合作过的单位
        mainBO.set("LINE",mainData.getString("CooperatedLine"));//已合作产品线
        mainBO.set("REMARK",mainData.getString("Memo"));//备注


        mainBO.set("ADDRESS",mainData.getString("TeamAdress"));//地址


        List<RowMap> contentData=SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMaps("SELECT * FROM ct_biddingteamlibrarydetail  WHERE Wiid = ?  ",mainData.getString("Wiid"));
        for(RowMap content:contentData){
            String uuid = UUIDGener.getUUID();
            BOCreateData subBOCreateData = new BOCreateData();
            boCreateDataList.add(subBOCreateData);
            subBOCreateData.setCreateUser(createUser);
            subBOCreateData.setBoName("BO_EU_BID_TEAM_APPLY_S");
            BO subBO = new BO();
            subBO.setId(uuid);
            subBOCreateData.setBo(subBO);
            subBO.set("USER_NAME",content.getString("Name"));//姓名
            subBO.set("DUTY",content.getString("Post"));//职务
            subBO.set("SKILL", content.getString("Major"));//专业及擅长
            subBO.set("ADDRESS",content.getString("Location"));//地址
            subBO.set("IS_ZZGMSB",content.getString("IsBuySocialSecurity"));//是否在中装购买社保
            subBO.set("PHONE", content.getString("Phone"));//电话
            super.addLogModel(historyTransContext, "ct_biddingteamlibrary", content.getString("id"), "BO_EU_BID_TEAM_APPLY_S", uuid, bindId);
        }
        historyTransContext.getProcessCreateContext().setBoCreateDatas(boCreateDataList);
        mainBOCreateData.setBoName("BO_EU_BID_TEAM_APPLY");

    }

    @Override
    protected String getDrpType() {
        return null;
    }

    @Override
    protected String getProcessDefId() {
        return "obj_88b821f2806c4f348870dfaea62c80b9";
    }

    @Override
    protected String getActivityDefId() {
        return "obj_45feb60f6bf44da2a8b2b56c20b0cbe2";
    }

    @Override
    protected String getTitle(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        String billNo = mainData.getString("BillNo");

        return "投标团队申请-历史数据迁移-"+billNo;
    }

    @Override
    protected String getEnCode(HistoryTransContext ctx) {
        RowMap mainData = ctx.getMainData();
        return mainData.getString("Wiid");
    }

    @Override
    protected String getOuterTable(DrpProcessCreateContext historyTransContext) {
        return "ct_biddingteamlibrary";
    }

    @Override
    protected String getPk(DrpProcessCreateContext historyTransContext) {
        RowMap mainData = historyTransContext.getMainData();
        return mainData.getString("MyId");
    }

    @Override
    protected List<RowMap> getMainDatas() {
        return SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMaps("SELECT * FROM ct_biddingteamlibrary");
    }

    @Override
    protected RowMap getMainData() {
        return null;
    }
}
